package com.xuecheng.content.api;

import com.xuecheng.content.model.dto.SaveTeachplanDto;
import com.xuecheng.content.model.dto.TeachplanDto;
import com.xuecheng.content.service.TeachplanService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(value = "课程计划编辑接口", tags = "课程计划编辑接口")
@RestController
public class TeachplanController {
    @Autowired
    private TeachplanService teachplanService;

    /**
     * @author ybl
     * @date 2023/3/4 17:44
     * @description 课程计划树形结构查询
     * @param courseId 课程Id
     * @return java.util.List<com.xuecheng.content.model.dto.TeachplanDto>
     * @since version-1.0
     */
    @ApiOperation(value = "课程计划树形结构查询")
    @ApiImplicitParam(value = "courseId", name = "课程Id", required = true, dataType = "Long", paramType = "path")
    @GetMapping("/teachplan/{courseId}/tree-nodes")
    public List<TeachplanDto> getTreeNodes(@PathVariable Long courseId) {
        return teachplanService.findTeachplayTree(courseId);
    }

    /**
     * @author ybl
     * @date 2023/3/4 17:45
     * @description 课程计划创建或修改接口
     * @param teachplan 课程计划数据
     * @since version-1.0
     */
    @ApiOperation("课程计划创建或修改")
    @PostMapping("/teachplan")
    public void saveTeachplan(@RequestBody SaveTeachplanDto teachplan) {
        teachplanService.saveTeachplan(teachplan);
    }

    /**
     * @author ybl
     * @date 2023/3/6 9:02
     * @description 课程计划删除接口
     * @param id 课程计划id
     * @since version-1.0
     */
    @ApiOperation("课程计划删除接口")
    @DeleteMapping("/teachplan/{id}")
    public void deleteTeachplan(@PathVariable Long id) {
        teachplanService.deleteTeachplan(id);
    }

    /**
     * @author ybl
     * @date 2023/3/6 11:37
     * @description 课程计划排序接口
     * @param move 移动类型
     * @param id 课程计划id
     * @since version-1.0
     */
    @ApiOperation("课程计划排序接口")
    @PostMapping("/teachplan/{move}/{id}")
    public void moveTeachplan(@PathVariable String move, @PathVariable Long id) {
        teachplanService.moveTeachplan(move, id);
    }
}
